home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 16 / myed106.zip / MYED.BAS next >
BASIC Source File  |  1987-10-15  |  42KB  |  1,414 lines

  1. ''''''''''''''''''''''''''''''''''MyEd 1.06''''''''''''''''''''''''''''''''''''
  2. '              Copyr. 1986, 1987 Nelson Ford All Rights Reserved
  3.  
  4. 'MyEd is a text editor written in MicroSoft's QuickBasic.
  5. 'It has been made as modular as possible so that you can very easily
  6. 'customize it to create a stand-alone word processor or incorporate it
  7. 'into your own program that might need editing capabilities.  Naturally,
  8. 'a knowledge of BASIC is required, as is a BASIC compiler.
  9.  
  10. 'A LIMITED LICENSE is hereby granted to individuals, schools and other non-
  11. 'profit entities to use all or part of the code in this program file for
  12. 'their own private use so long as proper credit and the following information
  13. 'is included in your source code:
  14.  
  15. 'COMMERCIAL USE...
  16. 'of all or part of this code, including use within a business, or
  17. 'ANY DISTRIBUTION of all or part of this code is allowed BY LICENSE ONLY.
  18. 'Unlicensed distribution or use of this code is a violation of copyright law
  19. 'and subject to civil and criminal prosecution, including substantial fines.
  20.  
  21. 'For licensing information, contact -
  22. '      Ford Software, 4845 Willowbend, Houston, TX 77035 713/721-5205
  23.  
  24. 'This file has been heavily annotated and long, descriptive names used for
  25. 'variables. Beyond this, we cannot provide support for people using this code
  26. 'under the free Limited License (see prior screen).  If you wish to register
  27. 'for telephone support, send $50 to the address above.  If you are new to
  28. 'QuickBASIC, you can order a QB Tutorial on disk for $9 from the same author.
  29.  
  30. 'This program uses CALL ABSOLUTE, which requires you to set up and use
  31. 'the file USERLIB.EXE. If you do not know how, please read your QB manual
  32. 'or call MicroSoft, not Ford Software.  USERLIB comes with QB.
  33.  
  34. 'Load this program into QB as follows:  QB MYED /L USERLIB.EXE
  35.  
  36. 'The program can be used with StayRes from MicroHelp. This add-on will allow
  37. 'you to make the program resident.  MicroHelp's phone number is 404-973-9272.
  38.  
  39. 'Programmers who submit significant enhancements to this code or who write
  40. 'public domain or shareware programs may be eligible for a free license to
  41. 'use this code.  Contact Ford Software for more information.  We are going
  42. 'to continue adding features to this code.  Updates will be made available
  43. 'and announced through The Public (software) Library and also CompuServe.
  44.  
  45. DEFINT A-Z
  46.  
  47. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  48. ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '
  49. ' 'This section of parameters should be modified to define the' '
  50. ' 'size and location of the edit area you wish to have:       ' '
  51.             First.Col =  1                            ' '
  52.             Last.Col  = 80                            ' '
  53.             First.Row =  1                            ' '
  54.             Last.Row  = 24                            ' '
  55.             Msg.Line  = 25                            ' '
  56.             Max.Lines =500                            ' '
  57.             DIM Text$(500), Text.Len(500)             ' '
  58. ' 'Dimension Text$ and Text.Len to the maximum number of lines' '
  59. ' 'Our testing indicates that a maximum of about 500 lines is ' '
  60. ' 'possible given BASIC's 64k data segment.                   ' '
  61. ' '                                                           ' '
  62. ' 'There are a couple of places where row and column numbers  ' '
  63. ' 'are hard-coded in.  To find these, search for LOCATE.      ' '
  64. ' '                                                           ' '
  65. ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '
  66. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  67. '============================================================================
  68. 10'                         MAIN PROGRAM LOOP
  69.  
  70. DIM Locks$(3), On.Off$(1), QPrint.CODE(127), Change$(10)
  71. ON ERROR GOTO Err.Trap
  72. GOSUB Initialize.Parameters
  73. GOSUB Load.File
  74. WHILE NOT the.end.of.the.universe  'loop for a long time
  75.   LOCATE Msg.Line,6,0: PRINT Line.Num;
  76.   LOCATE Msg.Line,16 : PRINT Char.Num;   'position cursor:
  77.   LOCATE First.Row+Line.Num-First.View.Line+1, First.Col+Char.Num-1,1
  78.   W$=""
  79.   WHILE W$=""
  80.     W$=INKEY$ : GOSUB Check.Lock.Status
  81.   WEND
  82.   IF LEN(W$) = 1_
  83.     THEN GOSUB Normal.key.pressed_
  84.     ELSE GOSUB Special.key.pressed
  85.   IF KY=Alt.X OR W$=Esc$ THEN GOSUB Save.Exit
  86. WEND
  87.  
  88. '============================================================================
  89. '                       Main program loop routines:
  90.  
  91. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  92.  Check.Lock.Status:
  93. 110'==============
  94. DEF SEG=&H40: New.Status=PEEK(&H17) AND 96: DEF SEG
  95. IF Lock.Status <> New.Status THEN
  96.   Addr=VARPTR(QPrint.CODE(0))
  97.   x$=Locks$(New.Status/32)
  98.   r110=25: c110=73
  99.   CALL ABSOLUTE(x$, r110, c110, Attrib, Addr)
  100.   Lock.Status = New.Status
  101.   IF Lock.Tone > 0 THEN SOUND Lock.Tone+New.Status, Duration!
  102. END IF
  103. RETURN
  104. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  105.  Normal.key.pressed:
  106. 120'===============
  107. IF W$=Entr$ THEN GOSUB Enter.Pressed_
  108.   ELSE IF W$=Bksp$ THEN GOSUB Backspace.Pressed_
  109.   ELSE GOSUB AlphaNumeric.Key.Pressed
  110. RETURN
  111. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  112.  
  113.  Special.key.pressed:   'INKEY$ scan code = 2 characters
  114. 130'================
  115. KY= ASC(RIGHT$(W$,1))
  116. 'cursor keys:
  117. IF KY=RT.Cursor THEN GOSUB Cursor.Right     ELSE_
  118. IF KY=LF.Cursor THEN GOSUB Cursor.Left      ELSE_
  119. IF KY=UP.Cursor THEN GOSUB Cursor.Up        ELSE_
  120. IF KY=DN.Cursor THEN GOSUB Cursor.Dn        ELSE_
  121. IF KY=Pg.Up     THEN GOSUB Page.Up          ELSE_
  122. IF KY=Pg.Dn     THEN GOSUB Page.Dn          ELSE_
  123. IF KY=Home      THEN GOSUB Move.Home        ELSE_
  124. IF KY=End.Key   THEN GOSUB Move.to.End      ELSE_
  125. IF KY=Del.Key   THEN GOSUB Del.Char         ELSE_
  126. IF KY=Ins.Key   THEN GOSUB Toggle.Insert    ELSE_
  127. IF KY=Ctrl.RT   THEN GOSUB Go.To.Next.Word  ELSE_
  128. IF KY=Ctrl.LF   THEN GOSUB Go.To.Prev.Word  ELSE_
  129. IF KY=Ctrl.End  THEN GOSUB Del.to.EOL       ELSE_
  130. IF KY=Ctrl.PgUp THEN GOSUB Go.To.File.Bgn   ELSE_
  131. IF KY=Ctrl.PgDn THEN GOSUB Go.To.File.End   ELSE_
  132. _' special functions:
  133. IF KY=Alt.B THEN GOSUB Define.Block     ELSE_
  134. IF KY=Alt.E THEN GOSUB Erase.Block      ELSE_
  135. IF KY=Alt.P THEN GOSUB Paste.Block      ELSE_
  136. IF KY=Alt.U THEN GOSUB Unmark.Block     ELSE_
  137. IF KY=Alt.D THEN GOSUB Del.Line         ELSE_
  138. IF KY=Alt.R THEN GOSUB Reform           ELSE_
  139. IF KY=Alt.I THEN GOSUB Toggle.Indent    ELSE_
  140. IF KY=Alt.W THEN Wrap.On = Not Wrap.On  ELSE_
  141. IF KY=Alt.F THEN GOSUB Find.Text        ELSE_
  142. IF KY=Alt.C THEN GOSUB Clear.Lines      ELSE_
  143. IF KY=Alt.N THEN GOSUB New.File         ELSE_
  144. IF KY=Alt.M THEN GOSUB Set.Rt.Margin    ELSE_
  145. IF KY=Alt.H THEN GOSUB Help.Screen      ELSE_
  146. IF KY=Alt.G THEN GOSUB Get.more.file    ELSE_
  147. IF KY=Alt.K THEN GOSUB Toggle.Auto.Cap
  148. RETURN
  149. '''''''''''''''''''''''''end of main loop routines''''''''''''''''''''''''''
  150. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  151. '                     "Normal Key Pressed" routines:
  152.  
  153. 'AlphaNumeric.Key.Pressed .. Add the keypress (W$) to the line of text.
  154. 'Enter.Pressed ............. Process Enter keypress.
  155. 'Backspace.Pressed ......... Process Backspace keypress.
  156.  
  157.  AlphaNumeric.Key.Pressed:
  158. 1210'====================
  159. IF Auto.Cap THEN GOSUB Cap.First.Letter
  160. IF Insert THEN                                   'If Insert mode is on then
  161.   IF Char.Num < Max.Text.Len THEN                'if there is room then
  162.     IF Text.Len(Line.Num) = Max.Text.Len-1 THEN  'if this is end of the line
  163.       IF Wrap.On THEN                            'the if wrap is on, go move
  164.            GOSUB Wrap                        'the last word on the line
  165.     ELSEIF EEK>0 THEN                        'otherwise, make a noise to
  166.            SOUND EEK,EEK!                    'indicate the end of line
  167.            RETURN                            'and return.
  168.       END IF    'Note that in the Insert mode, the cusor is not necessarily
  169.     END IF      'at the end of the line when you run out of room above.
  170.     'Now that there is room, insert the character:
  171.     MID$(Text$(Line.Num),Char.Num) = W$ + MID$(Text$(Line.Num),Char.Num)
  172.     Char.Num=Char.Num+1
  173.     Text.Len(Line.Num)=Text.Len(Line.Num)+1
  174.     GOSUB Prnt
  175.     RETURN
  176.   END IF
  177. END IF
  178. 'Insert is not on, so overtype:
  179. MID$(Text$(Line.Num),Char.Num,1)=W$
  180. Char.Num=Char.Num+1
  181. PRINT W$;
  182. IF Char.Num > Text.Len(Line.Num) THEN_
  183.   Text.Len(Line.Num) = Char.Num-1
  184. IF Char.Num > Max.Text.Len THEN
  185.   IF Wrap.On THEN GOSUB Wrap
  186.   IF Char.Num > Max.Text.Len THEN
  187.     Char.Num = Max.Text.Len
  188.     IF EEK>0 THEN SOUND EEK,EEK!
  189.   END IF
  190. END IF
  191. RETURN
  192. ''''''
  193.  
  194.  Enter.Pressed:
  195. 1220'=========
  196. IF Line.Num < Max.Lines THEN      '  if this is not the last line then
  197.   IF  Insert_                     '    if Insert is on
  198.   AND Last.Line < Max.Lines THEN_ '    and there is still room
  199.     GOSUB Split.Line              '      then split the line at the
  200.   IF Indent.On THEN_              '      cursor point.
  201.   GOSUB Find.Indent
  202.   Line.Num=Line.Num+1             '  increment line pointer
  203.   Char.Num=Indent+1               '  move character pointer to start.
  204.   IF Line.Num > Last.Line THEN_   '  increment Last.Line count
  205.     Last.Line=Line.Num            '    if necessary.
  206.   IF Line.Num > Last.View.Line THEN_
  207.     GOSUB Scroll.Up
  208. END IF
  209. GOSUB Prnt
  210. RETURN
  211.  
  212.  Backspace.Pressed:
  213. 1230'=============
  214.             'backspace key deletes the character at the cursor
  215. IF Char.Num>1 THEN  '  and moves the following text left 1 space, adding
  216.   Char.Num=Char.Num-1 '   a space at the end to keep the line length right.
  217.   Text$(Line.Num)=LEFT$(Text$(Line.Num),Char.Num-1)_
  218.          +MID$(Text$(Line.Num),Char.Num+1)+" "
  219.   Text.Len(Line.Num)=Text.Len(Line.Num)-1
  220.   Char.Num=Char.Num-1
  221. END IF
  222. GOSUB Prnt
  223.  
  224. ''''''''''''''''''''end of main "Normal Key Pressed" Routines''''''''''''''''
  225. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  226. '                       "Special Key Pressed" Routines:
  227.  
  228.  Cursor.Right:
  229. 1310'========
  230. IF Char.Num < Max.Text.Len_
  231.   THEN Char.Num = Char.Num + 1
  232. RETURN
  233.  
  234.  Cursor.Left:
  235. 1320'=======
  236. IF Char.Num > 1 THEN_
  237.   Char.Num = Char.Num - 1
  238. RETURN
  239.  
  240.  Cursor.Up:
  241. 1330'=====
  242. GOSUB Find.Text.Len
  243. IF Line.Num > 1 THEN
  244.      IF Line.Num = First.View.Line THEN
  245.        GOSUB Scroll.down
  246.      END IF
  247.      IF  Line.Num > Last.Line_
  248.      AND Text.Len(Line.Num) <> 0 THEN
  249.        Last.Line = Line.Num
  250.      END IF
  251.      Line.Num = Line.Num - 1
  252.   ELSE IF EEK>0 THEN SOUND EEK,EEK!
  253. END IF
  254. RETURN
  255.  
  256.  Scroll.Down:
  257. 1331'-------
  258. First.View.Line = First.View.Line - 1
  259. Last.View.Line = Last.View.Line - 1
  260. current.line = Line.Num
  261. FOR Line.Num = First.View.Line TO Last.View.Line
  262.   GOSUB Prnt
  263. NEXT
  264. Line.Num = current.line
  265. RETURN
  266.  
  267.  Cursor.Dn:
  268. 1340'=====
  269. GOSUB Find.Text.Len
  270. IF Line.Num < Max.Lines THEN
  271.      IF Line.Num = Last.View.Line THEN_
  272.        GOSUB Scroll.Up
  273.      IF  Line.Num > Last.Line_
  274.      AND Text.Len(Line.Num) <> 0 THEN_
  275.        Last.Line = Line.Num
  276.      Line.Num = Line.Num + 1
  277.   ELSE IF EEK>0 THEN SOUND EEK,EEK!
  278. END IF
  279. RETURN
  280.  
  281.  Page.Up:
  282. 1350'===
  283. IF First.View.Line - Num.View.Lines => 1 THEN
  284.        First.View.Line = First.View.Line - Num.View.Lines
  285.        Line.Num = Line.Num - Num.View.Lines
  286.        Last.View.Line = Last.View.Line - Num.View.Lines
  287.   ELSE First.View.Line = 1
  288.        Line.Num = 1
  289.        Last.View.Line = Num.View.Lines
  290.        IF EEK>0 THEN SOUND EEK,EEK!
  291. END IF
  292. GOSUB Prnt.Lines
  293. RETURN
  294.  
  295.  Page.Dn:
  296. 1360'===
  297. IF Last.View.Line + Num.View.Lines <= Max.Lines THEN
  298.        Last.View.Line = Last.View.Line + Num.View.Lines
  299.        Line.Num = Line.Num + Num.View.Lines
  300.        First.View.Line = First.View.Line + Num.View.Lines
  301.   ELSE First.View.Line = Max.Lines - Num.View.Lines + 1
  302.        Last.View.Line = Max.Lines
  303.        Line.Num = Last.View.Line
  304.        IF EEK>0 THEN SOUND EEK,EEK!
  305. END IF
  306. GOSUB Prnt.Lines
  307. RETURN
  308.  
  309.  Move.Home:
  310. 1370'=====
  311. IF Indent.On THEN_
  312.   GOSUB Find.Indent
  313. IF Char.Num > Indent+1_
  314.   THEN Char.Num=Indent+1_
  315.   ELSE Char.Num=1
  316. RETURN
  317.  
  318.  Move.to.End:
  319. 1380'=======
  320. IF Text.Len(Line.Num) < Max.Text.Len_
  321.   THEN Char.Num = Text.Len(Line.Num) + 1_
  322.   ELSE Char.Num = Text.Len(Line.Num)
  323. RETURN
  324.  
  325.  Del.Char:
  326. 1390'====
  327. IF Char.Num <= Text.Len(Line.Num) THEN
  328.        MID$(Text$(Line.Num), Char.Num)= _
  329.      MID$(Text$(Line.Num), Char.Num+1)+" "
  330.        Text.Len(Line.Num)=Text.Len(Line.Num)-1
  331.        GOSUB Prnt
  332.   ELSE dc.ln=Line.Num
  333.        GOSUB reform
  334.        Line.Num=dc.ln
  335. END IF
  336. RETURN
  337.  
  338.  Toggle.Insert:
  339. 1400'=========
  340. IF Insert=NO_
  341.   THEN Insert=Yes:_
  342.        Locate ,,1,CU1,CU2_  'change to a half-block cursor shape
  343.   ELSE Insert=NO:_
  344.        Locate ,,,CU2  'change to an underline cursor shape
  345. RETURN
  346.  
  347.  Go.To.Next.Word:
  348. 1410'===========
  349. IF Char.Num < Text.Len(Line.Num) + 1 THEN_
  350.   Char.Num = Char.Num + 1:_
  351.   WHILE Char.Num<Text.Len(Line.Num)+1_
  352.   AND Char.Num<Max.Text.Len_
  353.   AND (MID$(Text$(Line.Num),Char.Num-1,1)<>" "_
  354.   OR MID$(Text$(Line.Num),Char.Num-1,2)="  "):_
  355.     Char.Num=Char.Num-(Char.Num<Max.Text.Len):_
  356.   WEND
  357. RETURN
  358.  
  359.  Go.To.Prev.Word:
  360. 1420'===========
  361. IF Char.Num> 2 THEN
  362.     Char.Num=Char.Num-1
  363.     WHILE Char.Num >2_
  364.     AND  ( MID$(Text$(Line.Num),Char.Num-1,1)<>" "_
  365.     OR MID$(Text$(Line.Num),Char.Num-1,2) ="  " )
  366.       IF Char.Num > 2 THEN
  367.     Char.Num = Char.Num - 1
  368.       END IF
  369.     WEND
  370.     IF  Char.Num = 2_
  371.     AND MID$(Text$(Line.Num),Char.Num, 1) <> " " THEN_
  372.       Char.Num=1
  373.   ELSE Char.Num=1
  374. END IF
  375. RETURN
  376.  
  377.  Del.to.EOL:   'delete from the cursor position to the end of the line
  378. 1430'======
  379. Text$(Line.Num)=LEFT$(Text$(Line.Num), Char.Num - 1)_
  380.            +SPACE$(Max.Text.Len - Char.Num + 1)
  381. Text.Len(Line.Num)=Char.Num-1
  382. GOSUB Prnt
  383. RETURN
  384.  
  385.  Go.To.File.Bgn:
  386. 1440'==========
  387. IF First.View.Line=1 THEN IF EEK>0 THEN SOUND EEK,EEK!
  388. First.View.Line=1
  389. Last.View.Line = First.View.Line + Num.View.Lines -1
  390. GOSUB Prnt.Lines
  391. Line.Num=1
  392. RETURN
  393.  
  394.  Go.To.File.End:
  395. 1450'==========
  396. IF Last.View.Line=Last.Line THEN IF EEK>0 THEN SOUND EEK,EEK!
  397. Last.View.Line=Last.line
  398. First.View.Line = Last.View.Line - Num.View.Lines + 1
  399. GOSUB Prnt.Lines
  400. Line.Num=Last.View.Line
  401. RETURN
  402.  
  403.  Define.Block:
  404. 1460'========
  405. IF Line.Num > Block.Start_
  406. AND Block.Start > 0_
  407.   THEN Block.End = Line.Num_
  408.   ELSE Block.Start = Line.Num:_
  409.        IF Block.End=0_
  410.      THEN Block.End = Block.Start
  411. remember=Line.Num
  412. IF Line.Num < First.View.Line_
  413.   THEN Line.Num = First.View.Line_
  414.   ELSE Line.Num = Block.Start
  415. IF Block.End > Last.View.Line_
  416.   THEN b.e=Last.View.Line_
  417.   ELSE b.e=Block.End
  418. WHILE Line.Num <= b.e
  419.   Gosub Prnt
  420.   Line.Num=Line.Num+1
  421. WEND
  422. Line.Num=remember
  423. RETURN
  424.  
  425.  Erase.Block:
  426. 1470'=======
  427. IF Block.Start=0 THEN RETURN
  428. block = Block.End - Block.Start + 1
  429. Last.Line = Last.Line - Block
  430. FOR l = Block.Start TO Last.Line
  431.   Text$(l) = Text$(l+block)
  432.   Text.Len(l) = Text.Len(l+block)
  433. NEXT
  434. FOR l=Last.Line+1 TO Last.Line+block
  435.   Text$(l) = SPACE$(Max.Text.Len)
  436.   Text.Len(l) = 0
  437. NEXT
  438. 'The purpose of this next section of code is to try to keep the cursor on the
  439. 'line it's on after deleting the lines in the block and to keep the cursor
  440. 'line from moving.
  441. IF  Block.Start => First.View.Line_
  442. AND Block.Start <= Last.View.Line THEN
  443.     IF Line.Num > Block.Start THEN_
  444.       IF Line.Num <= Block.End_
  445.     THEN Line.Num = Block.Start_
  446.     ELSE Line.Num = Line.Num - block:_
  447.          IF First.View.Line - block > 0 THEN_
  448.            First.View.Line = First.View.Line - block:_
  449.            Last.View.Line = First.View.Line + Num.View.Lines -1
  450.   ELSEIF Block.End <= Last.View.Line THEN
  451.     Line.Num = Line.Num - block
  452.     First.View.Line = First.View.Line - block
  453.     Last.View.Line = First.View.Line + Num.View.Lines -1
  454. END IF
  455. GOSUB Unmark.Block
  456. RETURN
  457.  
  458.  Paste.Block:
  459. 1480'=======
  460. IF Block.Start = 0 THEN RETURN
  461. block = Block.End - Block.Start + 1
  462. IF Last.Line + block > Max.Lines THEN
  463.   Locate Msg.Line,25: PRINT SPACE$(45);: LOCATE Msg.Line,25: COLOR HL
  464.   PRINT "Not enough space left.";: COLOR FG
  465.   xxx$="": WHILE xxx$="": xxx$=INKEY$: WEND
  466.   LOCATE Msg.Line,25: PRINT SPACE$(40);
  467.   RETURN
  468. END IF
  469. FOR x=Last.Line+block TO Line.Num+block STEP -1
  470.   Text$(x) = Text$(x-block)
  471.   Text.Len(x) = Text.Len(x-block)
  472. NEXT
  473. FOR x=Line.Num TO Line.Num+block-1
  474.   Text$(x) = Text$(Block.Start + x-Line.Num)
  475.   Text.Len(x) = Text.Len(Block.Start + x-Line.Num)
  476. NEXT
  477. Last.Line = Last.Line + block
  478. GOSUB Prnt.Lines
  479. RETURN
  480.  
  481.  Unmark.Block:
  482. 1490'========
  483. Block.Start=0
  484. Block.End=0
  485. GOSUB Prnt.Lines
  486. RETURN
  487.  
  488.  Del.Line:
  489. 1500'====
  490. I=Line.Num
  491. FOR Line.Num=I TO Last.Line
  492.   Text$(Line.Num)=Text$(Line.Num+1)
  493.   Text.Len(Line.Num)=Text.Len(Line.Num+1)
  494.   IF Line.Num <= Last.View.Line THEN_
  495.     GOSUB Prnt
  496. NEXT
  497. Line.Num=I
  498. Last.Line=Last.Line-1
  499. RETURN
  500.  
  501.  Toggle.Indent:
  502. '=============
  503. IF Indent.On = Yes_
  504.   THEN Indent.On = No:_
  505.        Indent = 0_
  506.   ELSE Indent.On = Yes
  507. RETURN
  508.  
  509.  Find.Text:
  510. 1520'=====
  511. LOCATE Msg.Line,22: PRINT SPACE$(45);:
  512. LOCATE Msg.Line,22: COLOR HL
  513. PRINT "Text to find: ";: COLOR FG: col=POS(0)
  514. GOSUB Get.input
  515. srch$=LEFT$(Text$(0), Text.Len(0))
  516. IF W$=Esc$ THEN LOCATE,22: PRINT SPACE$(45): RETURN
  517. l=Line.Num+1
  518. 1521'
  519. WHILE l <> Line.Num_
  520. AND INSTR(Text$(l), srch$)=0
  521.   l=l+1
  522.   IF l > Last.Line THEN l=1
  523. WEND
  524. LOCATE Msg.Line,22: PRINT SPACE$(45);
  525. 1522'
  526. IF Line.Num <> l_
  527.   THEN
  528.     Line.Num=l
  529.     IF l > Last.View.Line_
  530.     OR l < First.View.Line THEN
  531.       IF Line.Num > (Num.View.Lines\2)_
  532.         THEN First.View.Line=Line.Num - Num.View.Lines\2_
  533.         ELSE First.View.Line=1
  534.       Last.View.Line=First.View.Line + Num.View.Lines - 1
  535.       GOSUB Prnt.Lines
  536.     END IF
  537.     Char.Num=Instr(Text$(l), srch$)
  538.     Locate First.Row+Line.Num-First.View.Line+1, First.Col+Char.Num-1,1
  539.     COLOR HL: PRINT srch$;: COLOR FG
  540.   ELSE
  541.     LOCATE Msg.Line,22: PRINT Srch$ " NOT FOUND.";
  542.     x$="": WHILE x$="": x$=INKEY$: WEND
  543.     LOCATE Msg.Line,22: PRINT SPACE$(45);
  544. END IF
  545. RETURN
  546.  
  547.  Clear.Lines:
  548. '===========
  549. LOCATE Msg.Line,25: PRINT SPACE$(45);: LOCATE Msg.Line,25
  550. COLOR HL
  551. PRINT "Confirm: Clear all lines (y/n)";
  552. COLOR FG
  553. x$="": WHILE x$="": x$=INKEY$: WEND
  554. LOCATE Msg.Line,25: PRINT SPACE$(45);
  555. IF x$="y" OR x$="Y" THEN GOSUB Clear.mem: Fi$="": GOSUB Prnt.Lines
  556.  
  557. RETURN
  558.  
  559.  Clear.mem:
  560. '---------
  561. FOR x=1 TO Max.Lines
  562.   Text$(x)=SPACE$(Max.Text.Len)
  563.   Text.Len(x)=0
  564. NEXT
  565. Line.Num=1
  566. Char.Num=1
  567. First.View.Line=1
  568. Last.View.Lines=Num.View.Lines
  569. Last.Line=0
  570. RETURN
  571.  
  572.  New.File:
  573. '========
  574. LOCATE Msg.Line,25: PRINT SPACE$(45);
  575. LOCATE Msg.Line,25: COLOR HL
  576. PRINT "Confirm: Load new file (y/n)";
  577. COLOR FG
  578. x$="": WHILE x$="": x$=INKEY$: WEND
  579. LOCATE Msg.Line,25: PRINT SPACE$(45);
  580. IF x$="y" OR x$="Y" THEN
  581.   FOR x=1 TO Max.Lines
  582.     Text$(x)=SPACE$(Max.Text.Len)
  583.     Text.Len(x)=0
  584.   NEXT
  585.   GOSUB Load.File
  586. END IF
  587. RETURN
  588.  
  589.  Set.Rt.Margin:
  590. '=============
  591. LOCATE Msg.Line,25: PRINT SPACE$(45);: LOCATE ,25
  592. 'PRINT "Enter new right margin: ";
  593. PRINT "Feature not implemented yet.";
  594. 'Last.Col=0
  595. 'WHILE (Last.Col < First.Col) or (Last.Col > 80)
  596.   'Locate Msg.Line,48
  597.   LINE INPUT; x$
  598.   'Last.Col=val(x$)
  599. 'WEND
  600. LOCATE ,25: PRINT SPACE$(45);
  601. 'Max.Text.Len=Last.Col-First.Col+1
  602. RETURN
  603.  
  604.  Get.more.file:
  605. '=============
  606. IF Next.section=0 THEN RETURN
  607. IF End.of.big.file THEN
  608.   LOCATE Msg.Line,25: PRINT SPACE$(45);: LOCATE ,25
  609.   COLOR HL: PRINT "* * * END OF FILE * * *";
  610.   w$="": WHILE w$="": w$=INKEY$: WEND
  611.   LOCATE Msg.Line,25: PRINT SPACE$(45);: LOCATE ,25
  612.   RETURN
  613. END IF
  614. LOCATE Msg.Line,25: PRINT SPACE$(45);: LOCATE ,25
  615. COLOR HL: PRINT "* GETTING NEXT SECTION *";
  616. GOSUB Save.it
  617. GOSUB Clear.Mem
  618. 1801'
  619. OPEN Fi$ FOR INPUT AS #1
  620. FOR x = 1 TO Next.section
  621.   LINE INPUT #1, A$
  622. NEXT
  623. GOSUB Read.in.text
  624. First.View.Line=1
  625. Last.View.Line=Num.View.Lines
  626. Current.Line=1
  627. GOSUB Prnt.lines
  628. RETURN
  629.  
  630.  Toggle.Auto.Cap:
  631. '===============
  632. 'The following routine toggles Auto.cap & changes the Auto.cap status display.
  633. '  (Auto.cap capitalizes the first letter of each word.)
  634. Auto.Cap=NOT Auto.Cap:_
  635. LOCATE Msg.Line,69
  636. COLOR HL
  637. Print On.Off$(1+Auto.Cap);
  638. COLOR FG
  639. IF EEK>0 THEN SOUND EEK,EEK!
  640. RETURN
  641.  
  642. Cap.First.Letter:
  643. '================
  644. IF Char.Num > 1 THEN_
  645. IF INSTR(Delimiter$, MID$(Text$(Line.Num),Char.Num-1,1)) > 0 THEN_
  646.   IF W$>="a" AND W$<="z" THEN_
  647.     W$=CHR$(ASC(W$)-32)
  648. RETURN
  649.  
  650.  Wrap:
  651. '====
  652. IF Line.Num=Max.Lines THEN
  653.   LOCATE Msg.Line,28: COLOR HL
  654.   PRINT "No more lines allowed.  Press C.";
  655.   IF EEK>0 THEN SOUND EEK,EEK!
  656.   xxx$="" : WHILE xxx$<>"C" AND xxx$<>"c" : xxx$=INKEY$: WEND
  657.   LOCATE Msg.Line,28: COLOR FG
  658.   PRINT SPACE$(40);
  659.   Char.Num=Char.Num-1
  660.   Last.Line=Max.Lines
  661.   RETURN
  662. END IF
  663.  
  664. IF Insert THEN_
  665.   IF Char.Num < Text.Len(Line.Num)+1_
  666.     THEN GOTO Insert.Wrap_
  667.     ELSE IF Line.Num < Last.Line_
  668.        THEN GOSUB Move.lines.down
  669.  
  670. IF W$=" " THEN_
  671.   GOSUB Find.text.len:_
  672.   Split.point=Max.Text.Len:_
  673.   GOTO Incr.pointers
  674.  
  675. Split.Point = Max.Text.Len - 1
  676. WHILE MID$(Text$(Line.Num), Split.Point ,1) <> " " AND Split.Point > 2
  677.   Split.Point = Split.Point - 1
  678. WEND
  679.  
  680. IF Indent.On THEN
  681.     GOSUB Find.Indent
  682. END IF
  683. IF Split.Point = Indent THEN_
  684.   Split.Point = Max.Text.Len - 1
  685.  
  686. IF Split.Point > 1 THEN
  687.   MID$(Text$(Line.Num+1),Indent+1) = MID$(Text$(Line.Num),Split.Point+1)
  688.   MID$(Text$(Line.Num),Split.Point+1) = SPACE$(Max.Text.Len-Split.Point)
  689.   GOSUB Prnt
  690.   GOSUB Find.Text.Len
  691. END IF
  692.  
  693. Incr.pointers:
  694. Line.Num=Line.Num+1
  695. GOSUB Find.Text.Len
  696. IF Insert_
  697.   THEN Char.Num=Text.Len(Line.Num)+1:_
  698.        Last.Line=Last.Line+1_
  699.   ELSE Char.Num=Indent+Max.Text.Len-Split.Point+1
  700.        IF Line.Num > Last.Line THEN Last.Line=Line.Num
  701. IF Line.Num > Last.View.Line THEN
  702.   GOSUB Scroll.Up
  703. END IF
  704. GOSUB Prnt
  705.  
  706. RETURN
  707.  
  708. Insert.Wrap:
  709. '----------
  710. Original.char.pos = Char.Num
  711. Char.Num = Char.Num + 1
  712. WHILE MID$(Text$(Line.Num), Char.Num, 1)<>" "_
  713. AND   Char.Num < Max.Text.Len
  714.   Char.Num = Char.Num + 1
  715. WEND
  716. IF Char.Num = Max.Text.Len THEN Char.Num = Original.char.pos + 1
  717. GOSUB Split.line
  718. Char.Num= Original.char.pos
  719. RETURN
  720.  
  721.  Move.lines.down:
  722. '===============
  723. Current.Line = Line.Num
  724. FOR Line.Num = Last.Line+1 TO Current.Line+2 STEP -1
  725.   Text$(Line.Num) = Text$(Line.Num-1)
  726.   Text.Len(Line.Num) = Text.Len(Line.Num-1)
  727.   IF Line.Num <= Last.View.Line THEN
  728.     GOSUB Prnt
  729.   END IF
  730. NEXT
  731. Line.Num = Current.Line
  732. Text$(Line.Num+1) = SPACE$(Max.Text.Len)
  733. Text.Len(Line.Num+1) = 0
  734. Last.Line = Last.Line + 1
  735. RETURN
  736.  
  737. '''''''''''''''''end of "AlphaNumeric Key Pressed" subroutines'''''''''''''''
  738. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  739. 2000'                     General Program Subroutines:
  740.  
  741. 'Prnt ................... Assm. subroutine to print a line of text quickly.
  742. 'Prnt.Lines ............. Print all the text lines on the screen.
  743. 'Find.Text.Len .......... Finds last character in the line of text.
  744. 'Find.Indent ............ Starts new line at same first char. as prior line.
  745. 'Scroll.Up .............. Scroll lines up on the screen.
  746. 'Split.Line ............. Divide a line at the cursor position.
  747. 'Reform ................. Reform a paragraph from the cursor line.
  748.  
  749. 2010'
  750.  Prnt:
  751. '====
  752. IF Line.Num > Last.View.Line THEN GOSUB Scroll.Up
  753. DEF SEG
  754. addr=VARPTR(QPrint.CODE(0))
  755. prnt.txt$ = Text$(Line.Num)
  756. IF Line.Num=0 THEN
  757.   row = csrlin
  758.   CALL ABSOLUTE(Text$(0), row, Col, Attrib, addr)
  759.   RETURN
  760. END IF
  761. prnt.row = First.Row + Line.Num - First.View.Line + 1
  762. IF Block.Start > 0 THEN
  763.   IF Line.Num => Block.Start_
  764.   AND Line.Num <= Block.End_
  765.   AND Attrib=FG.BG_
  766.     THEN Attrib=BG.FG
  767. END IF
  768. CALL ABSOLUTE(prnt.txt$, prnt.row, First.Col, Attrib, addr)
  769. Attrib=FG.BG
  770. RETURN
  771.  
  772. 2020'
  773.  Prnt.Lines:
  774. '==========
  775. current.line=Line.Num
  776. FOR Line.Num = First.View.Line TO Last.View.Line
  777.   GOSUB Prnt
  778. NEXT
  779. Line.Num=current.line
  780. COLOR HL,BG: LOCATE Msg.Line,1
  781. PRINT "LINE:     CHAR:         Editing " Fi$".  Alt-H for Help.";_
  782.        SPACE$(80-POS(0));
  783. COLOR FG,BG
  784. RETURN
  785.  
  786. 2030'
  787.  Find.text.len:  'sets Text.Len to last non-blank character in a line
  788. '=============
  789. Text.Len(Line.Num)=Max.Text.Len
  790. WHILE MID$(Text$(Line.Num), Text.Len(Line.Num), 1) = " "_
  791. AND   Text.Len(Line.Num) > 1
  792.   Text.Len(Line.Num) = Text.Len(Line.Num) - 1
  793. WEND
  794. IF  Text.Len(Line.Num)=1_
  795. AND LEFT$(Text$(Line.Num),1)=" "_
  796.   THEN Text.Len(Line.Num)=0
  797. RETURN
  798.  
  799. 2040'
  800.  Find.Indent:   'for auto-indent: starts new line at same cursor position
  801. '===========    '  as the preceeding line.
  802. Indent=0
  803. IF Text$(Line.Num) <> SPACE$(Max.Text.Len) THEN
  804.   WHILE Indent+1 < Max.Text.Len_
  805.   AND   MID$( Text$(Line.Num), Indent+1, 1 ) = " "
  806.     Indent = Indent + 1
  807.   WEND
  808. END IF
  809. RETURN
  810.  
  811. 2050'
  812.  Scroll.Up:
  813. '=========
  814. First.View.Line = First.View.Line + 1
  815. Last.View.Line = Last.View.Line + 1
  816. current.line = Line.Num
  817. FOR Line.Num = First.View.Line TO Last.View.Line
  818.   GOSUB Prnt
  819. NEXT
  820. Line.Num = current.line
  821. RETURN
  822.  
  823. 2060'
  824.  Split.line:
  825. '==========
  826. GOSUB Move.lines.down
  827. IF Indent.On THEN GOSUB Find.Indent
  828. Line.Num = Line.Num + 1
  829. MID$(Text$(Line.Num), Indent+1) = MID$(Text$(Line.Num-1), Char.Num)
  830. GOSUB Find.text.len
  831. IF Line.Num > Last.View.Line THEN
  832.   GOSUB Scroll.Up
  833. END IF
  834. GOSUB Prnt
  835. 'Remove split-off text from current line:
  836. Line.Num=Line.Num-1
  837. MID$(Text$(Line.Num), Char.Num) = SPACE$(Max.Text.Len)
  838. GOSUB Find.text.len
  839. GOSUB Prnt
  840. RETURN
  841.  
  842. 2070'
  843.  Reform:   'to reform a paragraph from the cursor line to the end of para.
  844. '======
  845. IF Text$(Line.Num) = SPACE$(Max.Text.Len) THEN RETURN
  846.  
  847. 'find the end of the paragraph:
  848. IF Indent.On THEN GOSUB Find.Indent
  849. End.of.Para=Line.Num
  850. WHILE MID$(Text$(End.of.Para+1), Indent+1, 3) <> "   "_
  851. AND End.of.Para < Last.Line
  852.   End.of.Para = End.of.Para + 1
  853. WEND
  854. IF Line.Num=End.of.Para THEN RETURN
  855. IF KY=Del.Key THEN End.of.Para=Line.Num+1: KY=0
  856.  
  857. Remember.line.num=Line.Num
  858. Blanks=0
  859.  
  860. WHILE Line.Num < End.of.Para
  861.   Next.Line=Line.Num+1
  862.   IF Indent.On THEN
  863.     Line.Num=Next.Line
  864.     GOSUB Find.Indent
  865.     Line.Num=Next.Line-1
  866.   END IF
  867.  
  868.   'Combine two lines if possible:
  869.   WHILE (Text.Len(Line.Num) + Text.Len(Next.Line) - Indent) < Max.Text.Len_
  870.   AND   Next.Line <= End.of.Para
  871.     MID$(Text$(Line.Num), Text.Len(Line.Num)+2)_
  872.       =MID$(Text$(Next.Line), Indent+1, Text.Len(Next.Line)-Indent)
  873.     Text.Len(Line.Num) = Text.Len(Line.Num) + Text.Len(Next.Line)-Indent + 1
  874.     Next.Line = Next.Line + 1
  875.   WEND
  876.  
  877.   IF Next.Line > Line.Num+1 THEN
  878.     Move.up=Next.Line - Line.Num -1
  879.     FOR x=Line.Num+1 to End.of.Para-Move.up
  880.       Text$(x)=Text$(x+Move.up)
  881.       Text.Len(x)=Text.Len(x+Move.up)
  882.     NEXT
  883.     FOR x=End.of.Para-Move.up+1 to End.of.Para
  884.       Text$(x)=SPACE$(Max.Text.Len)
  885.       Text.Len(x)=0
  886.     NEXT
  887.     End.of.Para=End.of.Para-Move.up
  888.     Blanks=Blanks+Move.up
  889.     Next.Line=Line.Num+1
  890.   END IF
  891.  
  892.   'find next word in next line and move it up to the current line:
  893.   IF Next.Line <= End.of.Para THEN
  894.     Next.Word = INSTR(Indent+2,Text$(Next.Line)," ")-1
  895.  
  896.     IF  Text.Len(Line.Num) +1 + Next.Word-Indent <= Max.Text.Len_
  897.     AND Next.Word > 0 THEN
  898.  
  899.       WHILE INSTR(Next.Word+2, Text$(Next.Line), " ") > 0_
  900.       AND   INSTR(Next.Word+2, Text$(Next.Line), " ")-1 < Text.Len(Next.Line)_
  901.       AND   INSTR(Next.Word+2, Text$(Next.Line), " ")-Indent_
  902.            + Text.Len(Line.Num)_
  903.               <= Max.Text.Len
  904.          Next.Word = INSTR(Next.Word+2, Text$(Next.Line), " ")-1
  905.       WEND
  906.  
  907.       'move word up from next line:
  908.       MID$(Text$(Line.Num), Text.Len(Line.Num)+2) = _
  909.              MID$(Text$(Next.Line), Indent+1, Next.Word-Indent)
  910.       Text.Len(Line.Num)= Text.Len(Line.Num) + Next.Word-Indent + 1
  911.       MID$(Text$(Next.Line), Indent+1) = MID$(Text$(Next.Line), Next.Word+2)_
  912.                        + SPACE$(Next.Word+1-Indent)
  913.       Text.Len(Next.Line)=Text.Len(Next.Line)-(Next.Word+1-Indent)
  914.     END IF
  915.   END IF
  916.   GOSUB Prnt
  917.   Line.Num=Line.Num+1
  918. WEND
  919. GOSUB Prnt
  920.  
  921. 'Move up rest of lines in the file:
  922. IF End.of.Para <> Last.Line THEN
  923.   IF End.of.Para + Blanks <> Last.Line THEN
  924.     FOR Line.Num = End.of.Para+1 TO Last.Line-Blanks
  925.       Text$(Line.Num)=Text$(Line.Num+Blanks)
  926.       Text.Len(Line.Num)=Text.Len(Line.Num+Blanks)
  927.       IF Line.Num <= Last.View.Line THEN
  928.         GOSUB Prnt
  929.       END IF
  930.     NEXT
  931.   END IF
  932.   FOR Line.Num = Last.Line-Blanks+1 to Last.Line
  933.     Text$(Line.Num)=SPACE$(Max.Text.Len)
  934.     Text.Len(Line.Num)=0
  935.     IF Line.Num <= Last.View.Line THEN
  936.       GOSUB Prnt
  937.     END IF
  938.   NEXT
  939. END IF
  940. Line.Num=End.of.Para
  941. Last.Line=Last.Line-Blanks
  942. IF Line.Num+1 < Max.Lines THEN Line.Num=Line.Num+1
  943.  
  944. RETURN
  945.  
  946. 2080'
  947.  Get.input:
  948. '=========
  949. l2080=Line.Num: Line.Num=0
  950. r2080=CSRLIN: c2080=POS(0)
  951. Text$(0)=space$(Max.Text.Len): W$="": Char.Num=1
  952. Text.Len(0)=0
  953. WHILE W$<>Entr$
  954.   IF LEN(W$) = 1 THEN GOSUB Normal.key.pressed
  955.   W$=""
  956.   LOCATE r2080,c2080+Char.num-1
  957.   WHILE W$=""
  958.     W$=INKEY$ : GOSUB Check.Lock.Status
  959.   WEND
  960. WEND
  961. Line.Num=l2080
  962. IF Text$(0)=SPACE$(Max.Text.Len) THEN Text$(0)=""
  963. RETURN
  964.  
  965.  
  966. '------------------------end of main loop subroutines-----------------------
  967.  
  968. '-------------------------------help screen----------------------------------
  969. 3000'
  970. Help.Screen:
  971. l=First.Row+1: h$=""
  972. RESTORE help.data
  973. read h$
  974. WHILE h$<>"done"
  975.   DEF SEG: Addr=VARPTR(QPrint.CODE(0))
  976.   x$=SPACE$(Max.Text.Len)
  977.   FOR n=First.Row+1 TO Last.Row
  978.     CALL ABSOLUTE(x$, n, First.Col, Attrib, Addr)
  979.   NEXT
  980.   WHILE l < Last.Row AND h$<>"done"
  981.     x$=SPACE$(Max.Text.Len)  'this line and the next either cuts the line
  982.     MID$(x$,1)=h$   'down or pads with blanks to fit the available space.
  983.     DEF SEG
  984.     Addr=VARPTR(QPrint.CODE(0))
  985.     CALL ABSOLUTE(x$, l, First.Col, Attrib, Addr)
  986.     l=l+1
  987.     READ h$
  988.   WEND
  989.   xxx$="": while xxx$="": xxx$=inkey$: wend
  990.   l=First.Row+1
  991. WEND
  992. GOSUB Prnt.Lines
  993. RETURN
  994.  
  995. help.data:
  996. data "Alt-B defines the beginning/end of a block of lines."
  997. data "Alt-C clears all lines."
  998. data "Alt-D deletes the line at the cursor position."
  999. data "Alt-E erases a block of lines."
  1000. data "Alt-F finds specified text"
  1001. data "Alt-G gets next section of a large file."
  1002. data "Alt-I toggles auto-indent."
  1003. data "Alt-K automatically caps the first letter of each word."
  1004. data "Alt-M set right Margin."
  1005. data "Alt-N to load a new file."
  1006. data "Alt-P pastes (copies) a block of lines."
  1007. data "Alt-R reforms paragraph from the current line down."
  1008. data "Alt-U unmarks a block of lines."
  1009. data "Alt-W toggles word-wrap on/off."
  1010. data "Alt-X save and exit."
  1011. data "Esc   exit without saving."
  1012. data "Ctrl-End deletes from the cursor to the end of the line."
  1013. data "Ins  toggles Insert mode."
  1014. data "ENTER pressed in the Insert mode splits a line at the cursor position."
  1015. data "Del at end of text joins two lines."
  1016. data "Cursor movement keys:"
  1017. data "    Up, Down, Left, Right."
  1018. data "    Home, End - Move to start or end of text. Again: start/end of line."
  1019. data "    Ctrl-Left Ctrl-Right - move cursor 1 word left or right."
  1020. data "done"
  1021. '--------------------------end of help screen--------------------------------
  1022.  
  1023. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  1024.  
  1025.              Initialize.Parameters:
  1026. 4000'
  1027. 'Get DOS command line parameters:
  1028.  
  1029. CMD$=command$
  1030. 'if /E present, use EMS memory:
  1031. IF INSTR(CMD$, "/E") or INSTR(CMD$, "/e") THEN TSR = -1
  1032. 'if /S present, use disk swapping:
  1033. s= INSTR(CMD$, "/S"): if s=0 then s=INSTR(CMD$, "/s")
  1034. IF s>0 THEN
  1035.   TSR = -1
  1036.   operation=7
  1037.   DIR$=MID$(CMD$, s+2)
  1038.   kshift=varptr(DIR$)
  1039.   CALL StayRes(operation, kscan, kshift, ecode)
  1040.   IF ecode=3 then
  1041.     PRINT "Must use DOS 3 for disk swapping.";
  1042.     x$="": WHILE x$="": x$=INKEY$: WEND
  1043.     END
  1044.   END IF
  1045.   IF ecode THEN
  1046.     PRINT "Can't use " dir$;
  1047.     x$="": WHILE x$="": x$=INKEY$: WEND
  1048.     END
  1049.   END IF
  1050. END IF
  1051.  
  1052. 'Variables for ForeGround, HighLight & BackGround colors:
  1053. f=INSTR(CMD$, "/FG"): if f=0 then f=INSTR(CMD$, "/fg")
  1054. b=INSTR(CMD$, "/BG"): if b=0 then b=INSTR(CMD$, "/bg")
  1055. h=INSTR(CMD$, "/HL"): if h=0 then h=INSTR(CMD$, "/hl")
  1056. IF f>0 THEN FG=VAL(MID$(CMD$,f+3,2)) ELSE FG=7
  1057. IF b>0 THEN BG=VAL(MID$(CMD$,b+3,2)) ELSE BG=0
  1058. IF h>0 THEN HL=VAL(MID$(CMD$,h+3,2)) ELSE HL=15
  1059.  
  1060. 'These tones are used to indicate change in -Lock status, etc:
  1061. IF INSTR(CMD$, "/q")=0 AND INSTR(CMD$, "/Q")=0 THEN
  1062.   Lock.Tone=400
  1063.   Duration!= .4
  1064.   EEK=4000
  1065.   EEK!=.04
  1066. END IF
  1067. ''''''''''''''''''''end of command line processing''''''''''''''''''
  1068.  
  1069.  
  1070. Char.Num=1   'points to cursor position within edit area.
  1071. Line.Num=1   'points to cursor row within edit area.
  1072. Last.Line=1  'last line with text in it.
  1073. First.View.Line=1   'line number of top line in edit area.
  1074. Last.View.Line=Last.Row-First.Row+1   'line number of last line in edit area.
  1075. Num.View.Lines = Last.View.Line       'max lines allowed in edit area.
  1076. Max.Text.Len=Last.Col-First.Col+1     'max line length.
  1077. First.Row=First.Row-1  'for easier computations.
  1078.  
  1079. Yes= -1
  1080. No =  0
  1081.  
  1082. Wrap.On = Yes   'word wrap may be toggled, but starts turned on.
  1083. Indent.On = Yes 'turn on automatic Indents.
  1084.  
  1085. FOR x=1 TO Max.Lines
  1086.   Text$(x)=SPACE$(Max.Text.Len)
  1087. NEXT
  1088.  
  1089. WIDTH 80
  1090. DEF SEG=0
  1091. COLR= (PEEK(&H410) AND &H30)<>&H30
  1092. DEF SEG
  1093. IF COLR THEN_ 'cursor shape definition:
  1094.        CU1=4:_
  1095.        CU2=7_
  1096.   ELSE CU1=11:_
  1097.        CU2=13
  1098.  
  1099. Delimiter$ = " ,.-;:=+(<#*{['/" + CHR$(34)
  1100.  
  1101. 'variables for displaying -Lock status:
  1102.  
  1103. Locks$(0)=STRING$(7," ")
  1104. Locks$(1)=STRING$(4," ")+"NUM"
  1105. Locks$(2)="CAP"+STRING$(4," ")
  1106. Locks$(3)="CAP"+CHR$(32)+"NUM"
  1107. On.Off$(0)="ON "
  1108. On.Off$(1)="OFF"
  1109.  
  1110. Entr$=CHR$(13)
  1111. Bksp$=CHR$(8)
  1112. Esc$=CHR$(27)
  1113. Entr.symbol$=" "+CHR$(17)+STRING$(2,196)+CHR$(217)+" "  'not used this pgm.
  1114.  
  1115. 'key scan codes:
  1116.  
  1117. LF.Cursor=75
  1118. RT.Cursor=77
  1119. Ctrl.LF=115
  1120. Ctrl.RT=116
  1121.  
  1122. UP.Cursor=72
  1123. DN.Cursor=80
  1124. PG.UP=73
  1125. PG.DN=81
  1126. Ctrl.PgUp=132
  1127. Ctrl.PgDn=118
  1128.  
  1129. Home=71
  1130. Ctrl.Home=119
  1131. End.Key=79
  1132. Ctrl.End=117
  1133. Ins.Key=82
  1134. Del.Key=83
  1135. ESC=27
  1136. Alt.B=48  'define block of lines
  1137. Alt.C=46  'clear all lines
  1138. Alt.D=32  'delete line at cursor
  1139. Alt.E=18  'erase block
  1140. Alt.F=33  'find text
  1141. Alt.G=34  'get next file section
  1142. Alt.H=35  'display help
  1143. Alt.I=23  'toggle auto-indent
  1144. Alt.K=37  'toggle auto-kap
  1145. Alt.L=38  '
  1146. Alt.M=50  'set right Margin
  1147. Alt.N=49  'new file
  1148. Alt.P=25  'paste block
  1149. Alt.R=19  'reform paragraph
  1150. Alt.S=31  'save file
  1151. Alt.U=22  'unmark block
  1152. Alt.W=17  'toggle word wrap
  1153. Alt.X=45  'exit
  1154.  
  1155. 'attribute codes FOR the asm subroutine:
  1156. FG.BG=FG+(BG AND 7)*16  'normal foreground-background
  1157. HL.BG=HL+(BG AND 7)*16  'highlighted foreground-normal background 'not used
  1158. BG.FG=BG+(FG AND 7)*16  'inverse video   'not used in this program
  1159.  
  1160. Attrib=FG.BG  'Attribute is normally set to the foreground/background colors.
  1161.           'The Attrib variable is used in the quick-print subroutine.
  1162.  
  1163. RESTORE Qprint.data
  1164. DEF SEG
  1165. FOR J=0 TO 106
  1166.   READ H$
  1167.   C$="&H"+H$
  1168.   X=VAL(C$)
  1169.   POKE (VARPTR(QPrint.CODE(0))+J),X
  1170. NEXT
  1171.  Qprint.data:
  1172. '-----------
  1173. DATA 55, 8B,EC, 8B,5E,08, 8B,3F, 4F, 8B,5E,0A, 8B,07, 48
  1174. DATA 8B,5E,0C, B5,00, 8A,0F, 80,F9,00, 74,37, 8B,77,02, BB,40,00
  1175. DATA 8E,C3, 26, F7,26,4A,00, 03,F8, D1,E7, 26, 8B,16,63,00
  1176. DATA 83,C2,06, B8,00,B8, 26, 8B,1E,10,00, 81,E3,30,00
  1177. DATA 83,FB,30, 75,03, B8,00,B0, 8B,5E,06, 8A,3F, 8E,C0
  1178. DATA E8,04,00, 5D, CA,08,00, AC, 8A,D8, EC, A8,01, 75,FB, FA, EC
  1179. DATA A8,01, 74,FB, 8B,C3, AB, FB, E2,EC, C3
  1180.  
  1181. LOCATE ,,1
  1182.  
  1183. IF TSR THEN     'This implements MicroHelp's code to make editor resident.
  1184.   Operation=0   ' can be purchased from MicroHelp.
  1185.   Kshift=12   '  \___Ctrl-Alt-E is the hot key. See StayRes manual to change.
  1186.   Kscan=18    '  /
  1187.   Ecode=100
  1188.   CALL StayRes(Operation, Kscan, Kshift, Ecode)
  1189.   IF Ecode > 0 THEN PRINT "StayRes Error" Ecode: stop
  1190. END IF
  1191. RETURN
  1192.  
  1193. 'end of Initialize.Parameters
  1194. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  1195. 5000
  1196.                   Load.File:
  1197.  
  1198.  'have to have a line number for error trapping
  1199. GOSUB Get.filename
  1200. IF f$<>"" THEN GOSUB Load.it
  1201. GOSUB Prnt.Lines
  1202. RETURN
  1203.  
  1204.  Get.filename:
  1205. '------------
  1206. COLOR FG,BG
  1207. CLS : f$="": New.Fi$="" : keep.going = yes
  1208. WHILE keep.going
  1209.   IF f$<>"" THEN FILES f$
  1210.   PRINT
  1211.   PRINT "Enter DIR or DIR A:FILENAME or DIR B:*.DOC, etc, for directories."
  1212.   PRINT "Just press ENTER to edit a new file or a file already in memory."
  1213.   IF NOT TSR THEN PRINT "Enter QUIT to exit the program."
  1214.   PRINT: PRINT "Name of file to edit: "; : col=pos(0)
  1215.   GOSUB Get.input
  1216.   f$=LEFT$(text$(0), Text.Len(0))
  1217.   PRINT: PRINT
  1218.   IF NOT TSR THEN IF f$="quit" OR f$="QUIT" THEN CLS : END
  1219.   IF LEFT$(f$+"   ",3)="DIR" OR LEFT$(f$+"   ",3)="dir" THEN
  1220.      IF LEN(f$) < 5 THEN
  1221.         f$="*.*"
  1222.        ELSE f$=mid$(f$,5)
  1223.      END IF
  1224.     ELSE keep.going = no
  1225.   END IF
  1226. WEND
  1227. Line.Num=1
  1228. RETURN
  1229.  
  1230.  Load.it:
  1231. '-------
  1232. IF Last.Line > 0 THEN GOSUB Clear.mem
  1233. Fi$=f$
  1234. OPEN Fi$ FOR INPUT AS #1
  1235. PRINT: PRINT: PRINT "Loading " Fi$: PRINT
  1236. Next.section=0
  1237. Trunc$="0"
  1238.  Read.in.text:
  1239. Start.section = Next.section
  1240. WHILE NOT EOF(1) AND Next.section = Start.section
  1241.   Last.Line = Last.Line + 1
  1242.   LINE INPUT #1, x$
  1243.   MID$(Text$(Last.Line),1)=x$
  1244.   Line.Num=Last.Line
  1245.   GOSUB Find.Text.Len
  1246.   IF LEN(x$) > Max.Text.Len THEN IF Trunc$<>"1" THEN GOSUB Long.line
  1247.   IF Last.Line => Max.Lines THEN GOSUB Big.file
  1248. WEND
  1249. CLOSE: Line.Num=1: Char.Num=1
  1250. IF Next.section > 0 THEN_
  1251.   IF Start.Section = Next.section_
  1252.     THEN End.of.big.file = yes:_
  1253.      Next.section=Last.line+1_
  1254.     ELSE End.of.big.file = no
  1255. RETURN
  1256.  
  1257.  Big.file:
  1258. '--------
  1259. IF Next.section = 0 THEN
  1260.   PRINT "File exceeds the maximum of" Max.Lines " lines (per section)."
  1261.   PRINT "At the present, MyEd allows only limited editing of longer files."
  1262.   PRINT "You can edit one piece of the file at a time, but not go back without
  1263.   PRINT "restarting the file over (ie: Alt-X).  A limit of 50 new lines can be
  1264.   PRINT "added to each section without starting over or deleting more lines."
  1265.   PRINT "The process of saving 500 lines and loading the next 500 lines is"
  1266.   PRINT "pretty slow, but it does make it possible to edit any size file."
  1267.   PRINT "To Get the next section while editing, press Alt-G."
  1268.   PRINT: PRINT "Make sure that enough disk space is available and"
  1269.   PRINT "enter drive and filename to use for new file: "; : col=POS(0)
  1270.   GOSUB get.input: PRINT
  1271.   New.Fi$=LEFT$(text$(0),Text.Len(0))
  1272.   OPEN New.Fi$ FOR OUTPUT AS #2: CLOSE #2  'make sure filename is ok.
  1273. END IF
  1274. Next.section = Start.section + Max.Lines-50
  1275. FOR x=Max.Lines-49 to Max.Lines
  1276.   Text$(x)=SPACE$(Max.Text.Len)
  1277.   Text.Len(x)=0
  1278. NEXT
  1279. Last.Line=450
  1280. RETURN
  1281.  
  1282.  Long.line:
  1283. '---------
  1284. WHILE INSTR("123",Trunc$)=0
  1285.   PRINT left$(x$, Max.Text.Len);
  1286.   COLOR BG,FG: PRINT mid$(x$, Max.Text.Len+1): COLOR FG,BG
  1287.   PRINT: PRINT "Line exceeds maximum line length of"Max.Text.Len".
  1288.   PRINT "1-Truncate  2-Wrap  3-Abort: ";
  1289.   Trunc$="": WHILE Trunc$="": Trunc$=INKEY$: WEND: PRINT
  1290.   PRINT "Keep asking each time? (y/n): ";
  1291.   ka$="": WHILE ka$="": ka$=INKEY$: WEND: PRINT
  1292. WEND
  1293. IF Trunc$="3" THEN RETURN 5000
  1294. IF Trunc$="2" AND Last.Line < Max.Lines THEN
  1295.   Last.Line = Last.Line +1
  1296.   MID$(Text$(Last.Line),1) = MID$(x$, Max.Text.Len+1)
  1297.   Line.Num=Last.Line
  1298.   GOSUB Find.Text.Len
  1299. END IF
  1300. IF INSTR("Nn", ka$)=0 THEN Trunc$="0"
  1301. RETURN
  1302.  
  1303. '''''''''''''''''''''''''''''end of Load.File''''''''''''''''''''''''''''''''
  1304. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  1305. 6000'                           Save file:
  1306.  Save.exit:
  1307.  
  1308. IF W$=Esc$ THEN_
  1309.   IF NOT TSR_
  1310.     THEN CLS: END_
  1311.     ELSE GOTO Exit.to.DOS
  1312.  
  1313. LOCATE Msg.Line,25: PRINT SPACE$(40);
  1314. LOCATE Msg.Line,25: ans$=""
  1315.  
  1316. IF New.Fi$<>"" THEN
  1317.   COLOR HL+15: PRINT "        Saving " New.fi$;
  1318.   GOTO Save.it
  1319. END IF
  1320.  
  1321. IF Fi$ <> "" THEN
  1322.   COLOR HL: PRINT "Save file as " Fi$ " (y/n) ";: COLOR FG
  1323.   ans$="": WHILE ans$="": ans$=INKEY$: WEND
  1324.   LOCATE Msg.Line,25: PRINT SPACE$(40);
  1325. END IF
  1326.  
  1327. IF ans$ <> "y" AND ans$ <> "Y" THEN
  1328.   LOCATE Msg.Line,25: COLOR HL
  1329.   PRINT "Enter new filename:  ";: COLOR FG : col=POS(0)
  1330.   GOSUB Get.input
  1331.   Fi$=LEFT$(Text$(0), Text.Len(0))
  1332.   IF Fi$="" THEN
  1333.     LOCATE Msg.Line,25: PRINT SPACE$(40);
  1334.     LOCATE Msg.Line,25: COLOR HL
  1335.     PRINT "Quit without saving (y/n)";
  1336.     COLOR FG
  1337.     abort$="": WHILE abort$="": abort$=INKEY$: WEND
  1338.     IF abort$<>"Y" AND abort$<>"y" THEN
  1339.        LOCATE Msg.Line,25: PRINT SPACE$(40);:
  1340.        KY=0
  1341.        RETURN
  1342.       ELSE GOTO Exit.to.DOS
  1343.     END IF
  1344.   END IF
  1345. END IF
  1346. LOCATE Msg.Line,25: PRINT SPACE$(40);
  1347. LOCATE Msg.Line,25: COLOR HL: PRINT "       Saving " Fi$;
  1348.  
  1349.  save.it:
  1350. IF New.Fi$<>""_
  1351.   THEN OPEN New.Fi$ FOR APPEND AS #1_
  1352.   ELSE OPEN Fi$ FOR OUTPUT AS #1
  1353. FOR x=1 TO Last.Line
  1354.   PRINT #1, LEFT$(Text$(x), Text.Len(x))
  1355. NEXT
  1356. CLOSE
  1357.  
  1358. IF KY=Alt.G THEN RETURN
  1359.  
  1360. IF New.Fi$<>"" THEN_
  1361.    IF NOT End.of.big.file THEN GOSUB Close.big.file
  1362.  
  1363.  Exit.to.DOS:
  1364. '-----------
  1365. LOCATE Msg.Line,25: PRINT SPACE$(40);
  1366. IF TSR THEN CALL StayRes(Operation, Kscan, Kshift, Ecode):_
  1367.         GOSUB Prnt.Lines
  1368. IF NOT TSR THEN END
  1369. RETURN
  1370.  
  1371.  Close.big.file:
  1372. '--------------
  1373. 6500'
  1374. OPEN Fi$ FOR INPUT AS #1
  1375. FOR x=1 TO Next.section : LINE INPUT #1, x$: NEXT
  1376. OPEN New.Fi$ FOR APPEND AS #2
  1377. WHILE NOT EOF(1)
  1378.   LINE INPUT #1, A$
  1379.   PRINT #2, A$
  1380. WEND
  1381. CLOSE
  1382. RETURN
  1383.  
  1384.  Err.Trap:
  1385. '========
  1386. 6600 CLOSE
  1387. LOCATE Msg.Line,25:PRINT SPACE$(45);:LOCATE Msg.Line,25
  1388. COLOR HL
  1389. IF ERR=64 THEN
  1390.      PRINT "Bad file name";
  1391.   ELSEIF ERR=61 THEN
  1392.      PRINT "Disk full";
  1393.   ELSEIF ERR=72 THEN
  1394.      PRINT "Disk media error";
  1395.   ELSEIF ERR=71 THEN
  1396.      PRINT "Drive not ready";
  1397.   ELSEIF ERR=53 THEN
  1398.      PRINT "File not found";
  1399.   ELSEIF ERR=7 OR ERR=14 THEN
  1400.      PRINT "Out of memory";
  1401.   ELSEIF ERR=76 THEN
  1402.      PRINT "Path not found";
  1403.   ELSEIF ERR=70 THEN
  1404.      PRINT "Disk/file write-protected";
  1405.   ELSE PRINT "Error number" ERR; "in line number" ERL;
  1406. END IF
  1407. COLOR FG: xe$=""
  1408. WHILE xe$="": xe$=INKEY$: WEND
  1409. IF ERL=1801 THEN RESUME 1801
  1410. IF ERL=5000 THEN f$="": RESUME 5000
  1411. IF ERL=6000 THEN RESUME 6000
  1412. IF ERL=6500 THEN RESUME 6500
  1413. GOTO Exit.to.DOS
  1414.